package cn.androidlongs.study.sub.action;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import cn.androidlongs.study.sub.service.SubService;
import cn.androidlongs.study.sub.vo.CommonUserSubjectModel;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class SubAction  extends ActionSupport implements ModelDriven<CommonUserSubjectModel>{


    public  SubService subService;
    private CommonUserSubjectModel userSubjectModel = new CommonUserSubjectModel();
    public void setSubService(SubService subService) {
	this.subService = subService;
    }
    public SubService getSubService() {
	return subService;
    }
    public void setUserSubjectModel(CommonUserSubjectModel userSubjectModel) {
	this.userSubjectModel = userSubjectModel;
    }


    /**
     * 获取所有的试题 
     * @return
     */
    public String getAllCommonSubList() {
	System.out.println("获取 所有的试题 ... ... ");
	String resultString = subService.getAllCommonSubListFunction();

	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(resultString);
	} catch (IOException e) {
	    e.printStackTrace();
	}
	return NONE;
    }

    public String subUUid;
    public void setSubUUid(String subUUid) {
	this.subUUid = subUUid;
    }
    public String getSubUUid() {
	return subUUid;
    }
    /**
     * 获取试题详情
     * @return
     */
    public String getSubDetaile() {
	System.out.println("获取试题详情" +getSubUUid());

	String resultString = subService.getSubDetaileFunction(getSubUUid());
	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(resultString);
	} catch (IOException e) {
	    System.out.println(" 查询试题详细情况异常 ");
	    e.printStackTrace();
	}
	return NONE;
    }

    private String subItemUUid;

    public String getSubItemUUid() {
	return subItemUUid;
    }
    public void setSubItemUUid(String subItemUUid) {
	this.subItemUUid = subItemUUid;
    }

    /**
     * 删除小题 
     * @return
     */
    public String deleteItem() {
	System.out.println("删除小题" +getSubUUid());

	String resultString = subService.deleteSubItemFunction(getSubUUid(),getSubItemUUid());
	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(resultString);
	} catch (IOException e) {
	    System.out.println(" 删除小题情况异常 ");
	    e.printStackTrace();
	}
	return NONE;
    }
    
    /**
     * 删除试题 
     * @return
     */
    public String deleteSub() {
	System.out.println("删除试题" +getSubUUid());
	String resultString = subService.deleteSubFunction(getSubUUid());
	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(resultString);
	} catch (IOException e) {
	    System.out.println(" 删除小题情况异常 ");
	    e.printStackTrace();
	}
	return NONE;
    }


    /*
     * 修改小题
     */
    public String alertItem() {
	return NONE;
    }
    @Override
    public CommonUserSubjectModel getModel() {
	return userSubjectModel;
    }


    private String subUUID;
    private String subTitle ;
    private String subFlagDes;
    private String itemTitle;
    private String itemSelectA;
    private String itemSelectB;
    private String itemSelectC;
    private String itemSelectD;
    private String itemSelectS;
    private int itemCount;



    public String getSubTitle() {
	return subTitle;
    }
    public void setSubTitle(String subTitle) {
	this.subTitle = subTitle;
    }
    public String getSubFlagDes() {
	return subFlagDes;
    }
    public void setSubFlagDes(String subFlagDes) {
	this.subFlagDes = subFlagDes;
    }
    public int getItemCount() {
	return itemCount;
    }
    public void setItemCount(int itemCount) {
	this.itemCount = itemCount;
    }
    public String getItemTitle() {
	return itemTitle;
    }
    public void setItemTitle(String itemTitle) {
	this.itemTitle = itemTitle;
    }
    public String getSubUUID() {
	return subUUID;
    }
    public void setSubUUID(String subUUID) {
	this.subUUID = subUUID;
    }
    public String getItemSelectA() {
	return itemSelectA;
    }
    public void setItemSelectA(String itemSelectA) {
	this.itemSelectA = itemSelectA;
    }
    public String getItemSelectB() {
	return itemSelectB;
    }
    public void setItemSelectB(String itemSelectB) {
	this.itemSelectB = itemSelectB;
    }
    public String getItemSelectC() {
	return itemSelectC;
    }
    public void setItemSelectC(String itemSelectC) {
	this.itemSelectC = itemSelectC;
    }
    public String getItemSelectD() {
	return itemSelectD;
    }
    public void setItemSelectD(String itemSelectD) {
	this.itemSelectD = itemSelectD;
    }
    public String getItemSelectS() {
	return itemSelectS;
    }
    public void setItemSelectS(String itemSelectS) {
	this.itemSelectS = itemSelectS;
    }
    /**
     * 添加试题 
     * @return
     */
    public String addSubItem() {

	System.out.println("添加试题");
	System.out.println(""+getItemSelectA());
	System.out.println(""+getItemTitle());
	String result = subService.addSubItemFuncton(getSubUUID(),getItemTitle(),getItemSelectA(),getItemSelectB(),getItemSelectC(),getItemSelectD(),getItemSelectS(),getItemCount());
	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(result);
	} catch (IOException e) {
	    System.out.println(" 删除小题情况异常 ");
	    e.printStackTrace();
	}

	return NONE;
    }

    
   
    private String subSign;
    private String subTitl;
    
    public String getSubTitl() {
        return subTitl;
    }
    public void setSubTitl(String subTitl) {
        this.subTitl = subTitl;
    }
    public String getSubSign() {
        return subSign;
    }
    public void setSubSign(String subSign) {
        this.subSign = subSign;
    }
    /**
     * 添加 试题
     */
    public String addCommonSub() {
	System.out.println("添加试题 "+getSubTitl()+"\t\t"+getSubSign());
	String result = subService.addCommSubFunction(getSubTitl(),getSubSign());
	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(result);
	} catch (IOException e) {
	    System.out.println(" 添加试题 情况异常 ");
	    e.printStackTrace();
	}
	return NONE;
    }
    /**
     * 修改主题的 信息内容 
     * @return
     */
    public String alertMainSub() {
	System.out.println("修改试题信息 ... "+getSubFlagDes()+"\t"+getSubTitle());
	String resultString  = subService.alertSubFunction(getSubUUID(),getSubFlagDes(),getSubTitle());

	// 获得response对象,项页面输出:
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("text/html;charset=UTF-8");

	try {
	    response.getWriter().write(resultString);
	} catch (IOException e) {
	    System.out.println(" 删除小题情况异常 ");
	    e.printStackTrace();
	}

	return NONE;
    }
}
